package com.example.springaop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
//@Aspect
public class AspectDemo {
    @Pointcut("execution(* com.example.springaop.controller.*.*(..))")
    public void pt(){};
    @Before("pt()")
    public void doBefore(){
        log.info("do before……");
    }
    @After("pt()")
    public void doAfter(){
        log.info("do after……");
    }

    /**
     * Around一定要有返回结果
     */
    @Around("pt()")
    public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        log.info("do around before……");
        Object result = proceedingJoinPoint.proceed();
        log.info("do around after……");
        return result;
    }

    @AfterReturning("pt()")
    public void doAfterReturning(){
        log.info("do after returning……");
    }

    @AfterThrowing("pt()")
    public void doAfterThrowing(){
        log.info("do after throwing……");
    }

}
